package com.lagou.service;

import com.lagou.dao.TokenDao;
import com.lagou.dao.UserDao;
import com.lagou.edu.pojo.LagouToken;
import com.lagou.edu.pojo.LagouUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.Optional;

@Service
@Transactional
public class TokenService {
    @Autowired
    private TokenDao tokenDao;

    /**
     * 根据token查询用户信息
     * @param lagouToken
     * @return
     */
    public Optional<LagouToken> find(LagouToken lagouToken) {
        Example<LagouToken> example = Example.of(lagouToken);
        return tokenDao.findOne(example);
    }

    public void insert(LagouToken lagouToken) {
        tokenDao.save(lagouToken);
    }

    public long count(LagouToken lagouToken) {
        Example<LagouToken> example = Example.of(lagouToken);
        return tokenDao.count(example);
    }
}


